<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="" prop="memberId">
      <el-input v-model="dataForm.memberId" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="1：注册，2.注销，3.绑定网盘，4更改手机号，5更改登录密码，6更改支付密码，7接触绑定，20其他" prop="operationType">
      <el-input v-model="dataForm.operationType" placeholder="1：注册，2.注销，3.绑定网盘，4更改手机号，5更改登录密码，6更改支付密码，7接触绑定，20其他"></el-input>
    </el-form-item>
    <el-form-item label="操作时间" prop="operateTime">
      <el-input v-model="dataForm.operateTime" placeholder="操作时间"></el-input>
    </el-form-item>
    <el-form-item label="操作者ID" prop="operatorId">
      <el-input v-model="dataForm.operatorId" placeholder="操作者ID"></el-input>
    </el-form-item>
    <el-form-item label="操作内容" prop="operation">
      <el-input v-model="dataForm.operation" placeholder="操作内容"></el-input>
    </el-form-item>
    <el-form-item label="1成功，2失败，3取消" prop="result">
      <el-input v-model="dataForm.result" placeholder="1成功，2失败，3取消"></el-input>
    </el-form-item>
    <el-form-item label="" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder=""></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          memberId: '',
          operationType: '',
          operateTime: '',
          operatorId: '',
          operation: '',
          result: '',
          createTime: ''
        },
        dataRule: {
          memberId: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          operationType: [
            { required: true, message: '1：注册，2.注销，3.绑定网盘，4更改手机号，5更改登录密码，6更改支付密码，7接触绑定，20其他不能为空', trigger: 'blur' }
          ],
          operateTime: [
            { required: true, message: '操作时间不能为空', trigger: 'blur' }
          ],
          operatorId: [
            { required: true, message: '操作者ID不能为空', trigger: 'blur' }
          ],
          operation: [
            { required: true, message: '操作内容不能为空', trigger: 'blur' }
          ],
          result: [
            { required: true, message: '1成功，2失败，3取消不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/disk/memberlog/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.memberId = data.memberLog.memberId
                this.dataForm.operationType = data.memberLog.operationType
                this.dataForm.operateTime = data.memberLog.operateTime
                this.dataForm.operatorId = data.memberLog.operatorId
                this.dataForm.operation = data.memberLog.operation
                this.dataForm.result = data.memberLog.result
                this.dataForm.createTime = data.memberLog.createTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/disk/memberlog/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'memberId': this.dataForm.memberId,
                'operationType': this.dataForm.operationType,
                'operateTime': this.dataForm.operateTime,
                'operatorId': this.dataForm.operatorId,
                'operation': this.dataForm.operation,
                'result': this.dataForm.result,
                'createTime': this.dataForm.createTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
